/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jsf.service;

import com.jsf.service.Car;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.LazyDataModel;

/**
 *
 * @author Admin
 */
@Named
@ViewScoped
public class DataTableLazy implements Serializable{
    
    private String test;
    
    private List<Car> cars;
    
    private LazyService service;
    
    private LazyDataModel<Car> lazyModel;
    
    private Car selectedCar;
     
    @PostConstruct
    public void init() {
        test="001";
        System.out.println("com.mycompany.service.DataTableLazy.init()");
        service = new LazyService();
        lazyModel = new LazyModel(service.createCars(200));
        
    }

    /**
     * @return the test
     */
    public String getTest() {
        return test;
    }

    /**
     * @param test the test to set
     */
    public void setTest(String test) {
        this.test = test;
    }

    /**
     * @return the cars
     */
    public List<Car> getCars() {
        return cars;
    }

    /**
     * @param cars the cars to set
     */
    public void setCars(List<Car> cars) {
        this.cars = cars;
    }

  

    /**
     * @return the selectedCar
     */
    public Car getSelectedCar() {
        return selectedCar;
    }

    /**
     * @param selectedCar the selectedCar to set
     */
    public void setSelectedCar(Car selectedCar) {
        this.selectedCar = selectedCar;
    }
    
     public void onRowSelect(SelectEvent event) {
        FacesMessage msg = new FacesMessage("Car Selected", ((Car) event.getObject()).getRandomId());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    /**
     * @return the lazyModel
     */
    public LazyDataModel<Car> getLazyModel() {
        return lazyModel;
    }

    /**
     * @param lazyModel the lazyModel to set
     */
    public void setLazyModel(LazyDataModel<Car> lazyModel) {
        this.lazyModel = lazyModel;
    }
    
     public void setService(LazyService service) {
        this.service = service;
    }
}
